package com.example.demo.mapper;

import com.example.demo.entity.UserMes;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author:王声基
 * @date:2019/12/25
 * @decription:用户数据操作
 */
@Mapper
public interface UserMapper {

    //插入user表
    @Insert("insert into User(username,password,email,gen_time) values(#{username},#{password},#{email},#{genTime})")
    public int insertUser(User user);

    //通过id查询user表
    @Select("select tu_id,username,password,email,gen_time from User where tu_id=#{uid}")
    public UserMes selectUserById(int uid);

    //通过名字查询user表
    @Select("select u_id,username,password,email,gen_time from User where username=#{username}")
    public UserMes selectUserByName(String username);

    //姓名模糊查询
    @Select("select u_id,username,password,email,gen_time from User where username like #{username} ")
    public List<UserMes> selectUserByName0(String username);

    //删除user表
    @Delete("delete from UserMes where u_id=#{uid}")
    public int deleteUserById(int uid);

    //删除user角色
    @Delete("delete from TUserRoleRelation where User_id=#{uid}")
    public int deleteUserRole(int uid);

    //更新user表
    @Update("update UserMes set username=#{username},password=#{password},email=#{email} where u_id=#{uid}")
    public int updateUserById(int uid,String username, String password, String email);

    //查询user角色
    @Select("select Role_id from TUserRoleRelation where User_id=#{uid}")
    public List<Integer> selectUserRole(int uid);

    @Insert("insert into TUserRoleRelation(User_id,Role_id) values(#{User_id},#{Role_id})")
    public int insertUserRole(int User_id,int Role_id);


}
